<template>
  <view :style="colorStyle">
    <navTitle :styleType="'black'" :title="'签到'" />
    <image
      src="http://xpj40szpt.signalpha.cn/img/img82.png"
      class="bg"
      mode="widthFix"
    ></image>
    <view
      class="infobox1 cfff f28 fontWeight"
      @click="gourl('/pages/signIn/list')"
    >
      签到记录
    </view>
    <view class="infobox2">
      <view class="block1 c00406C f28 fontWeight"> 连续签到 </view>
      <view class="block2 flex aitems c00406C fontWeight">
        <view class="info1 f80">
          {{ info.continuousCount }}
        </view>
        <view class="info2 f36"> 天 </view>
      </view>
      <view class="block3 cfff 228">
        {{ info.todaySignFlag ? "今日已签到" : "今日未签到" }}
        <!-- +1积分，+50经验 -->
      </view>
    </view>
    <view class="infobox3">
      <view class="block1 flex aitems jcenter">
        <image src="@/static/img83.png" @click="last" mode=""></image>
        <view class="info1 c1F1F1F fontWeight f44">
          {{ year }} 年 {{ month }} 月
        </view>
        <image src="@/static/img84.png" @click="next" mode=""></image>
      </view>
      <view class="block2">
        <view class="info1 flex aitems">
          <view
            class="tipbox1 c525252 f32 fontWeight"
            v-for="(item, index, key) in week"
            :key="key"
          >
            {{ item.name }}
          </view>
        </view>
        <view class="info1 flex aitems wrap fontWeight">
          <view
            class="tipbox1"
            v-for="(item, index, key) in info.firstDayOfWeek"
            :key="key"
            v-if="info.firstDayOfWeek !== 7"
          >
          </view>
          <view
            class="tipbox1 c1F1F1F f32 flex aitems jcenter"
            v-for="(item, index, key) in info.signCalendar"
            :key="key"
          >
            <view :class="info.today == index ? 'tip1' : ''">
              {{ index }}
            </view>
            <view class="dian" v-if="item"> </view>
          </view>
        </view>
      </view>
    </view>
    <view class="infobox4">
      <view class="block1 cfff f32 fontWeight" @click="userSignSignIn">
        {{ info.todaySignFlag ? "已签到" : "立即签到" }}
      </view>
    </view>
  </view>
</template>

<script>
import {
  userSignSignIn,
  userSignInfo,
  updateParent,
} from "@/servers/servers.js";
import { HTTP_STATUS } from "@/servers/config.js";
import colors from "@/mixins/color";
import { go, loading, msg } from "../../utils/wxAPI";
import { getGloBalData, getToken } from "../../utils/storage";
import { handleLoopCallBack } from "../../utils/util";
export default {
  mixins: [colors],
  data() {
    return {
      year: new Date().getFullYear(),
      month: new Date().getMonth() + 1,
      week: [
        {
          name: "日",
        },
        {
          name: "一",
        },
        {
          name: "二",
        },
        {
          name: "三",
        },
        {
          name: "四",
        },
        {
          name: "五",
        },
        {
          name: "六",
        },
      ],
      info: {},
      options: {},
    };
  },
  async onLoad(options) {
    this.options = options;
    if (getToken()) {
      this.userSignInfo();
      if (this.options.uid) {
        updateParent({
          id: this.options.uid,
        });
      }
    } else {
      handleLoopCallBack(async () => {
        this.userSignInfo();
        if (this.options.uid) {
          updateParent({
            id: this.options.uid,
          });
        }
      });

      // #ifdef H5
      if (getEnv() == "H5") {
        uni.reLaunch({
          url: "/pages/login/login",
        });
      }
      // #endif
    }
  },
  methods: {
    async userSignInfo() {
      let { data } = await userSignInfo({
        year: this.year,
        month: this.month,
      });
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        console.log(data);
        this.info = data.data;
      }
    },
    last() {
      if (this.month == 1) {
        this.year -= 1;
        this.month = 12;
      } else {
        this.month -= 1;
      }
      this.userSignInfo();
    },
    next() {
      if (this.month == 12) {
        this.year += 1;
        this.month = 1;
      } else {
        this.month += 1;
      }
      this.userSignInfo();
    },
    gourl(url) {
      go(url);
    },
    async userSignSignIn() {
      loading();
      let { data } = await userSignSignIn();
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        msg("签到成功");
        this.userSignInfo();
      }
    },
  },
  onShareAppMessage: function (e) {
    return {
      title: "签到",
      path: `/pages/signIn/index?uid=${getGloBalData("userinfo").id}`,
    };
  },
};
</script>
<style>
/* #ifdef MP-WEIXIN */
page {
  background: #e2e5ff;
}

/* #endif */
</style>
<style lang="scss" scoped>
page {
  background: #e2e5ff;
}

.bg {
  width: 100%;
  position: absolute;
  top: 0;
}

.infobox1 {
  position: absolute;
  background: rgba(0, 0, 0, 0.4);
  width: 172rpx;
  height: 64rpx;
  border-radius: 30rpx 0 0 30rpx;
  line-height: 64rpx;
  text-align: center;
  top: 210rpx;
  right: 0;
  z-index: 999;
}

.infobox2 {
  position: relative;
  z-index: 1;
  top: 210rpx;
  margin: 0 30rpx 0;

  .block1 {
  }

  .block2 {
    margin: 24rpx 0 0;
  }

  .block3 {
    margin: 36rpx 0 0;
    border-radius: 42rpx;
    background: #5ccedd;
    padding: 5rpx 16rpx;
    display: inline-block;
  }
}

.infobox3 {
  position: relative;
  z-index: 1;
  top: 210rpx;
  margin: 48rpx 30rpx 0;
  background: #fff;
  border-radius: 30rpx;
  padding: 50rpx 0 0;

  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, #fff 100%);
  box-shadow: drop-shadow(0px 0px 33.2rpx rgba(0, 0, 0, 0.04));
  backdrop-filter: blur(28.100000381469727rpx);

  .block1 {
    image {
      width: 38rpx;
      height: 38rpx;
    }

    .info1 {
      margin: 0 105rpx;
    }
  }

  .block2 {
    margin: 34rpx 0 0;

    .info1 {
      .tipbox1 {
        width: 14.28%;
        height: 90rpx;
        line-height: 90rpx;
        text-align: center;
        position: relative;

        .tip1 {
          width: 60rpx;
          height: 60rpx;
          line-height: 60rpx;
          text-align: center;
          background: #5ccedd;
          border-radius: 50%;
        }

        .dian {
          background: #5ccedd;
          width: 10rpx;
          height: 10rpx;
          border-radius: 50%;
          position: absolute;
          bottom: 0;
        }
      }
    }
  }
}

.infobox4 {
  position: relative;
  z-index: 1;
  top: 210rpx;
  margin: 92rpx 30rpx 0;

  .block1 {
    padding: 22rpx 0;
    text-align: center;
    border-radius: 72rpx;
    border: 4rpx solid rgba(255, 255, 255, 0.6);
    background: linear-gradient(180deg, #5cddc6 0%, #5ccedd 100%);
  }
}
</style>
